<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>index</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
    <style>
      .hello {
        background-image: linear-gradient(45deg,red,yellow,green);
        color: white;
        border-radius: 5px;
        padding: 10px;
      }
    </style>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo"></div>

    <script type="text/javascript">
      // 创建一个Hello组件
      const Hello = Vue.extend({
        name:'Hello',
        template:'<h2 class="hello">你好</h2>'
      })
      // 全局注册组件
      Vue.component('Hello',Hello)
      
      // 创建Person组件
      const Person = Vue.extend({
        name:'Person',
        template:`
          <div>
            <Hello/>
            <h2>人员信息</h2>
            <h3>姓名：{{personName}}</h3>
            <h3>年龄：{{personAge}}</h3>
          </div>
        `,
        data(){
          return {
            personName:'张三',
            personAge:18,
          }
        }
      })

      // 创建School组件
      const School = Vue.extend({
        name:'School',
        template:`
          <div>
            <Hello/>
            <h2>学校信息</h2>
            <h3>校名：{{schoolName}}</h3>
            <h3>地址：{{schoolAddress}}</h3>
          </div>
        `,
        data(){
          return {
            schoolName:'尚硅谷',
            schoolAddress:'北京',
          }
        }
      })

      // 创建App组件
      const App = Vue.extend({
        name:'App',
        template:`
          <div>
            <Person/>
            <hr>
            <School/>
          </div>
        `,
        components:{Person,School} //局部注册
      })

      new Vue({
        el:'#demo',
        template:'<App/>',
        components:{App}
      })
      
      
    </script>
  </body>
</html>